package com.home766.controller.shop;

import com.home766.dto.AreaDto;
import com.home766.dto.DictionaryDTO;
import com.home766.entity.Shops;
import com.home766.service.IDictionaryService;
import com.home766.service.ShopsService;
import net.biz.Page;
import net.biz.Pageable;
import net.biz.controller.shop.BaseController;
import net.biz.entity.Area;
import net.biz.entity.ProductCategory;
import net.biz.service.AreaService;
import net.biz.service.ProductCategoryService;
import net.biz.service.ProductService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * Controller - 门店
 * 
 * @author Ricky
 * @version 1.0
 */
@Controller("shopController")
@RequestMapping("/shops")
public class ShopsController extends BaseController {
	
	@Resource(name = "shopsServiceImpl")
	private ShopsService shopsService;
	@Resource(name="areaServiceImpl")
	private AreaService areaService;
	@Resource(name="dictionaryServiceImpl")
	private IDictionaryService iDictionaryService;

	@Resource(name = "productServiceImpl")
	private ProductService productService;
	@Resource(name = "productCategoryServiceImpl")
	private ProductCategoryService productCategoryService;
	/***
	 * 列表
	 * @param shops
	 * @param pageable
	 * @param model
	 * @return
	 */
	@RequestMapping("/list")
	public String list(Shops shops, Pageable pageable, ModelMap model){
		/*门店类型*/
		List<DictionaryDTO> dv = iDictionaryService.searchChildren(39L);
		Page<Shops> page = shopsService.getShopsReceptionList(shops, pageable);
		/*填充页面三级联动*/
		List<Area> parentList = areaService.findRoots();
		List<AreaDto> getChildrenListOne = areaService.findChildren(shops.getProvinceId());
		List<AreaDto> getChildrenListTwo = areaService.findChildren(shops.getCityId());
		/*获取维护的顶级区域*/
		List<Area> shopsArea = shopsService.getShopsArea();
		/*获取维护的下级区域*/
		List<Area> shopsAreaChildren = shopsService.getShopsAreaChildren(shops.getProvinceId());
		/*获取维护的下级区域*/
		List<Area> shopsAreaChildrens = shopsService.getShopsAreaChildrens(shops.getCityId());
		
		model.addAttribute("parentList",parentList);
		model.addAttribute("getChildrenListOne",getChildrenListOne);
		model.addAttribute("getChildrenListTwo",getChildrenListTwo);
		model.addAttribute("dv",dv);
		model.addAttribute("page",page);
		model.addAttribute("shops",shops);
		model.addAttribute("shopsArea",shopsArea);
		model.addAttribute("shopsAreaChildren",shopsAreaChildren);
		model.addAttribute("shopsAreaChildrens",shopsAreaChildrens);
		return "/shop/store/list";
	}
	@RequestMapping("/listt")
	public String listt(Shops shops, Pageable pageable, ModelMap model){
		Long id1 = new Long(79);
		Long id2 = new Long(82);
		Long id3 = new Long(84);
		Long id4 = new Long(172);
		Long id5 = new Long(145);
		ProductCategory warmCategory = productCategoryService.find(id1);
		ProductCategory acCategory = productCategoryService.find(id2);
		ProductCategory waterCategory = productCategoryService.find(id3);
		ProductCategory seimCategory = productCategoryService.find(id4);
		ProductCategory windCategory = productCategoryService.find(id5);

		//Pageable pageable = new Pageable(pageNumber, pageSize);
		//model.addAttribute("productCategory", productCategory);
		//model.addAttribute("pageNumber", pageNumber);
		//model.addAttribute("pageSize", pageSize);
		model.addAttribute("pageWarm", productService.findPage(warmCategory, null, null, null, null, null, null, true, true, null, false, null, null, null, pageable));
		model.addAttribute("pageAC", productService.findPage(acCategory, null, null, null, null, null, null, true, true, null, false, null, null, null, pageable));
		model.addAttribute("pageWater", productService.findPage(waterCategory, null, null, null, null, null, null, true, true, null, false, null, null, null, pageable));
		model.addAttribute("pageSeim", productService.findPage(seimCategory, null, null, null, null, null, null, true, true, null, false, null, null, null, pageable));
		model.addAttribute("pageWind", productService.findPage(windCategory, null, null, null, null, null, null, true, true, null, false, null, null, null, pageable));
		return "/shop/index";
  }
	/***
	 * 根据省/市查询下级
	 * @param provinceId
	 * @return
	 */
	@RequestMapping(value = "/getChildrenByParentId")
	@ResponseBody
	public List<AreaDto> getChildrenByParentId(Long provinceId){
		List<AreaDto> getChildrenList = areaService.findChildren(provinceId);
		return getChildrenList;
	}
}